package com.piesat.quake.business.device.model;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableField;
import com.piesat.quake.business.device.mqtt.anno.CharField;
import com.piesat.quake.business.device.mqtt.anno.ConvertField;
import com.piesat.quake.business.device.mqtt.anno.IgnoreField;
import com.piesat.quake.business.device.mqtt.convert.IpConvert;

import java.io.Serializable;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 *
 * </p>
 *
 * @author ${author}
 * @since 2023-03-13
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("d_network_data")
public class NetworkData implements Serializable {

    private static final long serialVersionUID = 1L;

    @IgnoreField
    @TableId(value = "id", type = IdType.INPUT)
    private String id;

    @IgnoreField
    @TableField("type")
    private Byte type;

    @ConvertField(length = 4, convert = IpConvert.class)
    @TableField("address")
    private String address;

    @TableField("port")
    private Short port;

    @CharField(32)
    @TableField("username")
    private String username;

    @CharField(128)
    @TableField("password")
    private String password;

    @CharField(32)
    @TableField("path")
    private String path;

    public NetworkData asMqtt(){
        type=ConfigurationUpdate.Network.MQTT;
        return this;
    }

    public NetworkData asFtp(){
        type=ConfigurationUpdate.Network.FTP;
        return this;
    }

    public NetworkData asFtpLog(){
        type=ConfigurationUpdate.Network.FTP_LOG;
        return this;
    }

    public NetworkData asUpdate(){
        type=ConfigurationUpdate.Network.UPDATE;
        return this;
    }
}
